/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cc.altius.web.controller;

import cc.altius.model.Designation;
import cc.altius.service.DesignationService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.support.SessionStatus;

/**
 *
 * @author santosh
 */
@Controller
public class DesignationController {

    @Autowired
    private DesignationService designationService;
    @ModelAttribute("designationList")
    List<Designation> getDesignationList (){
        return this.designationService.getDesignationList();
    }

    @RequestMapping(value = "/designation/addDesignation.htm", method = RequestMethod.GET)
    public String getShowDesignationPage(ModelMap modelMap) {
        System.out.println("inside of controller in get page of add desiganation");
        Designation designation = new Designation();
        modelMap.addAttribute("designation", designation);
        return "designation/addDesignation";
    }

    @RequestMapping(value = "/designation/addDesignation.htm", method = RequestMethod.POST)
    public String addDesignationPage(@ModelAttribute("designation") Designation designation, Error error, SessionStatus sessionStatus) {
        int designationId = this.designationService.addDesignation(designation);
        System.out.println("designationId" + designationId);
        System.out.println("inside of controller in post page of add desiganation");
        return "redirect:addDesignation.htm?msg=Succesfully Added Ambulance";
    }

    @RequestMapping(value = "/designation/listDesignation.htm", method = RequestMethod.GET)
    public String showDesignationPage(ModelMap modelMap) {
        return "designation/listDesignation";
    }
}
